package com.itycu.server.service.business;

import java.util.List;
import com.itycu.server.utils.DateUtils;
import com.itycu.server.dto.business.PraPracticesDto;
import com.itycu.server.core.AbstractService;
import com.itycu.server.utils.SecurityUtils;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.itycu.server.mapper.business.PraPracticesMapper;
import com.itycu.server.domain.business.PraPractices;

/**
 * 练习子Service业务层处理
 *
 * @author itycu
 * @date 2025-02-20
 */
@Service("praPracticesService")
public class PraPracticesService extends AbstractService<PraPractices> {
    @Resource
    private PraPracticesMapper praPracticesMapper;

    /**
     * 查询练习子列表
     *
     * @param praPractices 练习子
     * @return 练习子
     */
    public List<PraPracticesDto> list(PraPractices praPractices) {
        praPractices.setOrderByClause("id desc");
        return praPracticesMapper.listByCondition(praPractices);
    }

    /**
     * 根据id获取练习子详细信息
     */
    @Override
    public PraPracticesDto findById(Long id) {
        return praPracticesMapper.findById(id);
    }

    /**
     * 保存练习子
     *
     * @param praPractices 练习子
     * @return 结果
     */
    @Override
    public int save(PraPractices praPractices) {
        int count;
        if (praPractices.getId() == null) {
            praPractices.setCreateBy(SecurityUtils.getUserId());
            praPractices.setCreateTime(DateUtils.getNowDate());
            count = super.save(praPractices);
        } else {
            praPractices.setUpdateBy(SecurityUtils.getUserId());
            praPractices.setUpdateTime(DateUtils.getNowDate());
            count = super.update(praPractices);
        }
        return count;
    }
}
